﻿using System.Threading;
using Android.App;
using Android.Hardware;
using Android.Os;
using Android.Util;
using Android.View;
using Android.Widget;
using Dot42.Manifest;
using Java.Lang;

[assembly: Application("Li pong")]
[assembly: UsesOpenGL(0x00020001)]
[assembly: MetaData(Name = "anyDensity", Value = "false")]
namespace LeePong
{
    [Activity(Icon = "Icon", ScreenOrientation = ScreenOrientations.Landscape)]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstance)
        {
            base.OnCreate(savedInstance);

            // global errors handler
            Thread.SetDefaultUncaughtExceptionHandler(new ExceptionHandler());

            // full screen
            RequestWindowFeature(Window.FEATURE_NO_TITLE);
            GetWindow().SetFlags(IWindowManager_LayoutParams.FLAG_FULLSCREEN, IWindowManager_LayoutParams.FLAG_FULLSCREEN);

            // set content
            SetContentView(R.Layouts.Layout1);

            var mainLayout = FindViewById<RelativeLayout>(R.Ids.mainLayout);
            //mainLayout.SetBackgroundResource(R.Drawables.LandTexture);

            var panel = new GameSurface(this, mainLayout);
            mainLayout.AddView(panel);
        }

        //protected override void OnStart()
        //{
        //    base.OnStart();

        //    var mainLayout = FindViewById<LinearLayout>(R.Ids.mainLayout);

        //    var width = mainLayout.GetMeasuredWidth();
        //    var height = mainLayout.GetBottom();
        //}


        public class ExceptionHandler : System.Threading.Thread.IUncaughtExceptionHandler
        {
            public void UncaughtException(System.Threading.Thread thread, System.Exception ex)
            {
                Log.D("-------------", ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
    }
}